package vistas;

import com.sun.corba.se.impl.orbutil.graph.Graph;
import controladores.Controlador;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Image;
import javax.swing.ImageIcon;
import vistas.estructuras.Panel;

public class VentanaFinDeJuego extends javax.swing.JFrame implements InterfazFinDeJuego {

    /**
     * Creates new form VentanaGanador
     */
    public VentanaFinDeJuego() {
        initComponents();
        setLocationRelativeTo(null);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        saludo = new javax.swing.JLabel();
        partida = new javax.swing.JLabel();
        resultado = new javax.swing.JLabel();
        jugarOtraVez = new javax.swing.JButton();
        movimientos = new javax.swing.JLabel();
        puntaje = new javax.swing.JLabel();
        panelImagen = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Juego Finalizado");
        setResizable(false);

        jPanel1.setBackground(java.awt.Color.black);

        saludo.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        saludo.setForeground(new java.awt.Color(255, 255, 255));

        partida.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        partida.setForeground(new java.awt.Color(255, 255, 255));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(saludo, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(75, 75, 75)
                .addComponent(partida, javax.swing.GroupLayout.PREFERRED_SIZE, 252, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(138, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(saludo, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(partida, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(12, Short.MAX_VALUE))
        );

        resultado.setFont(new java.awt.Font("Tahoma", 1, 36)); // NOI18N
        resultado.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

        jugarOtraVez.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jugarOtraVez.setText("Jugar otra vez");

        movimientos.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        movimientos.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

        puntaje.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        puntaje.setForeground(new java.awt.Color(51, 153, 0));
        puntaje.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

        javax.swing.GroupLayout panelImagenLayout = new javax.swing.GroupLayout(panelImagen);
        panelImagen.setLayout(panelImagenLayout);
        panelImagenLayout.setHorizontalGroup(
            panelImagenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );
        panelImagenLayout.setVerticalGroup(
            panelImagenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(movimientos, javax.swing.GroupLayout.PREFERRED_SIZE, 404, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(resultado, javax.swing.GroupLayout.PREFERRED_SIZE, 264, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jugarOtraVez)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(puntaje, javax.swing.GroupLayout.PREFERRED_SIZE, 404, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(panelImagen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(resultado, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(movimientos, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(puntaje, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelImagen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, Short.MAX_VALUE)
                .addComponent(jugarOtraVez, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(VentanaFinDeJuego.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(VentanaFinDeJuego.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(VentanaFinDeJuego.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(VentanaFinDeJuego.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new VentanaFinDeJuego().setVisible(true);
            }
        });
    }
    
    // Métodos de InterfazVista
    @Override
    public void setControlador(Controlador controlador) {
        jugarOtraVez.addActionListener(controlador);
    }
    
    
    @Override
    public void arrancar() {
        // Visualizo la ventana
        setVisible(true);
    }
    
    
    @Override
    public void cerrar () {
        dispose();
    }
    
    // Métodos de InterfazFinDeJuego
    @Override
    public void setSaludo (String string) {
        saludo.setText("Hola "+string);
    }
    
    
    @Override
    public void setTituloPartida (int nivel) {
        String stringNivel = "";
        if (nivel ==1) stringNivel = "Facil";
        else if (nivel == 2) stringNivel = "Moderada";
        else if (nivel == 3) stringNivel = "Dificil";
        partida.setText("Partida "+stringNivel);
    }
    
    
    @Override
    public void setResultadoGanador(int movimientosRestantes, int puntajeObtenido) {
        resultado.setForeground(new Color(51,153,0));
        resultado.setText("GANASTE !!");
        String stringMovimientos = Integer.toString(movimientosRestantes);
        String stringPuntaje = Integer.toString(puntajeObtenido);
        movimientos.setText("Te sobraron "+stringMovimientos+" movimientos");
        puntaje.setText("Obtuviste un puntaje de "+stringPuntaje+" puntos");
        try {
            Image imagen = new ImageIcon(".\\src\\vistas\\estructuras\\imagenes\\Trofeo.png").getImage();
            setImagen(imagen);
        } catch (Exception e) {
           System.out.println("Error en asignar imagen al panel!");
        }
        panelImagen.setVisible(true);
    }
    
    @Override
    public void setImagen (Image imagen){
        Panel panel = new Panel();
        panel.setImagen(imagen);
        panel.setSize(100, 100);
        panelImagen.setLayout(new GridLayout(1,1));
        panelImagen.setPreferredSize(new Dimension(100, 100));
        panelImagen.add(panel);
    }

    @Override
    public void setResultadoPerdedor() {
        resultado.setForeground(new Color(255,0,0));
        resultado.setText("PERDISTE !!");
        try {
            Image imagen = new ImageIcon(".\\src\\vistas\\estructuras\\imagenes\\CaraTriste.png").getImage();
            setImagen(imagen);
        } catch (Exception e) {
           System.out.println("Error en asignar imagen al panel!");
        }
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jPanel1;
    private javax.swing.JButton jugarOtraVez;
    private javax.swing.JLabel movimientos;
    private javax.swing.JPanel panelImagen;
    private javax.swing.JLabel partida;
    private javax.swing.JLabel puntaje;
    private javax.swing.JLabel resultado;
    private javax.swing.JLabel saludo;
    // End of variables declaration//GEN-END:variables

}
